//
//  ViewController.m
//  JPProjectConfigureDemo
//
//  Created by Carpenter on 2018/2/6.
//  Copyright © 2018年 carpenter. All rights reserved.
//

#import "ViewController.h"
#import "JPProjectConfigure.h"
#import "pushViewController.h"
typedef NS_ENUM(NSInteger ,ViewControllerCellFunctionType) {
  
    ViewControllerCellFunctionType_Defaults = 0,
    
    ViewControllerCellFunctionType_Web = 1000,
    
    ViewControllerCellFunctionType_Net = 1001,
    
    ViewControllerCellFunctionType_push = 1002,
};

@interface ViewController ()

@end

static NSString * const K_dic_key_identifier = @"identifier";

static NSString * const K_dic_key_title      = @"title";

@implementation ViewController

-(NSMutableArray *)sourceArrayM{
    return @[
               @[
                 @{K_dic_key_title     :@"网页",
                   K_dic_key_identifier:@(ViewControllerCellFunctionType_Web),
                   },
                 @{K_dic_key_title     :@"请求",
                   K_dic_key_identifier:@(ViewControllerCellFunctionType_Net),
                   },
                 @{K_dic_key_title     :@"pushx",
                   K_dic_key_identifier:@(ViewControllerCellFunctionType_push),
                   },
                ],
            
             ].mutableCopy;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self.tableView reloadData];
    
    
    
    
}
// self.toolbarItems = items;
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.sourceArrayM.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.sourceArrayM[section] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary * dic = self.sourceArrayM[indexPath.section][indexPath.row];
    
    JPBaseCell * cell = [JPBaseCell jp_cellForTableView:tableView];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.textLabel.text = dic[@"title"];
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary * dic = self.sourceArrayM[indexPath.section][indexPath.row];
    
    ViewControllerCellFunctionType identifier = [dic[K_dic_key_identifier] integerValue];
    
    switch (identifier) {
        case ViewControllerCellFunctionType_Web:
        {
            NSURL * url = [NSURL URLWithString:@"https://www.baidu.com"];
            
//            JPBaseWebController * vc = [[JPBaseWebController alloc] initWithURL:url];
// 
//            [self.navigationController pushViewController:vc animated:true];
        }
            break;
        case ViewControllerCellFunctionType_Net:
        {
            //免费api https://blog.csdn.net/c__chao/article/details/78573737
            //新闻接口
            [[JPNetManager rac_GET:@"https://www.apiopen.top/journalismApi" parameters:nil] subscribeNext:^(id  _Nullable x) {
                
            }];
        }
    case ViewControllerCellFunctionType_push:
        {
            pushViewController * vc = [pushViewController new];
            
            [self.navigationController pushViewController:vc animated:true];
        }
        break;
            break;
        default:
            break;
    }
    
 
}

@end
